package com.lgz.dbcourse.mapper;

import com.lgz.dbcourse.dto.AudienceDTO;
import com.lgz.dbcourse.dto.MyMovie;
import com.lgz.dbcourse.entity.AudienceEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @Author: LGZ
 * @Date: 2021/4/11 10:53
 * @Description:
 */
public interface AudienceMapper {
    /**
     * TODO
     * @Description
     * @Author lgz
     * @Date 2021/4/11 10:59
     * @param audienceEntity : 观众实体
     * @return : com.lgz.dbcourse.dto.AudienceDTO
     */
    @Select("SELECT * FROM audience WHERE audience_phone = MD5(#{audienceEntity.audiencePhone})")
    AudienceDTO getAudienceByPhone(@Param("audienceEntity")AudienceEntity audienceEntity);

    /**
     * TODO
     * @Description 存在则不操作，不存在就插入
     * @Author lgz
     * @Date 2021/4/27 16:17
     * @param audienceEntity :
     * @return : void
     */
    void insertAudience(@Param("audienceEntity")AudienceEntity audienceEntity);

    /**
     * TODO
     * @Description
     * @Author lgz
     * @Date 2021/4/28 17:10
     * @param phone :
     * @return : com.lgz.dbcourse.dto.MyMovie
     */
    @Select("SELECT audience_display, hall.hall_name, seat.seat_code, movie.movie_name, movie_schedule.start_time " +
            "FROM audience, hall, seat, movie, movie_schedule, movie_seat " +
            "WHERE audience.audience_id = #{audienceId} " +
            "AND audience.audience_id = movie_seat.audience_id " +
            "AND seat.seat_id = movie_seat.seat_id " +
            "AND movie_schedule.schedule_id = movie_seat.schedule_id " +
            "AND seat.hall_id = hall.hall_id " +
            "AND movie.movie_id = movie_schedule.movie_id " +
            "ORDER BY movie_schedule.start_time DESC")
    MyMovie[] getMyMovie(@Param("audienceId")Long audienceId);
}
